import openpyxl
from config import users_list, exclusions


def writeExcel(file, sheet_index):
    workbook = openpyxl.load_workbook(file)
    worksheet = workbook.worksheets[0]
    nrows = worksheet.max_row
    ncols = worksheet.max_column
    print(nrows, ncols)

    exclusion_lists = []
    for i in range(len(exclusions)):
        exclusion_lists.append(exclusions[i].get('clientid'))
    # print(exclusion_lists)

    # 根据历史数据已录入负责人的email，获取负责人对应的clientid
    new_dict = {}
    for row in range(2, nrows+1):
        clientids = worksheet.cell(row, 2).value
        owner = worksheet.cell(row, 12).value
        # print('clientids', clientids)
        clientids_list = str(clientids).split(',')
        # print('clientids_list', clientids_list)
        new_clientids_list = []
        for i in clientids_list:
            if i not in exclusion_lists:
                new_clientids_list.append(i)
        new_clientids_list.reverse()
        print(new_clientids_list)
        print(new_clientids_list[0], owner)
        print('---------------------------------------------------------------------')

        # 根据历史数据已录入负责人的email，获取负责人对应的clientid
        new_dict[new_clientids_list[0]] = owner
    # 根据历史数据已录入负责人的email，获取负责人对应的clientid
    print('new_dict', new_dict)
    list = []
    for k, v in new_dict.items():
        if v == 'xxx':
            list.append(k)
    print(list)


if __name__ == '__main__':
    # file = 'log_2021-04-17_2021-04-20_sensitivedata.xlsx'
    file = 'old_processing_data/log_2021-05-01_2021-05-16_sensitivedata.xlsx'
    # data = get_data(file, 0)
    writeExcel = writeExcel(file, 0)
